#ifndef __PROC_H__
#define __PROC_H__
#include "type.h"
#include "kconst.h"
#include "sysdescriptor.h"
#define	phys_copy	memcpy
#define	phys_set	memset
#define NR_TASKS		3	//任务数
#define NR_PROC			3  	//用户进程数
#define PROC_SZ         (NR_TASKS + NR_PROC)   //进程数

#define STACK_SIZE_TESTA	0x8000

#define STACK_SIZE_TOTAL	STACK_SIZE_TESTA

void* va2la(int pid, void *va);

typedef struct s_stackframe {
	u32	gs;		/* \                                    */
	u32	fs;		/* |                                    */
	u32	es;		/* |                                    */
	u32	ds;		/* |                                    */
	u32	edi;		/* |                                    */
	u32	esi;		/* | pushed by save()                   */
	u32	ebp;		/* |                                    */
	u32	kernel_esp;	/* <- 'popad' will ignore it            */
	u32	ebx;		/* |                                    */
	u32	edx;		/* |                                    */
	u32	ecx;		/* |                                    */
	u32	eax;		/* /                                    */
	u32	retaddr;	/* return addr for kernel.asm::save()   */
	u32	eip;		/* \                                    */
	u32	cs;		/* |                                    */
	u32	eflags;		/* | pushed by CPU during interrupt     */
	u32	esp;		/* |                                    */
	u32	ss;		/* /                                    */
}STACK_FRAME;

typedef struct s_proc {
	STACK_FRAME regs;          /* process registers saved in stack frame */

	u32 ldt_sel;               /* gdt selector giving ldt base and limit */
	DESCRIPTOR ldts[LDT_SIZE]; /* local descriptors for code and data */
	u32 pid;                   /* process id passed in from MM */
	char p_name[16];           /* name of the process */
	int nr_tty;					/* 进程所属的TTY */
	int p_flags;
	MESSAGE *p_msg;
	int p_recvfrom;
	int p_sendto;
	int has_int_msg;
	struct s_proc * q_sending;
	struct s_proc * next_sending;

}PROCESS;

#define proc2pid(x) (x - proc_table)

typedef void (*task_f)();

typedef struct _task 
{
	task_f initial_eip;
	int stacksize;
	char name[32];
} TASK;

void reset_msg(MESSAGE *p);
int msg_receive(struct s_proc *current, int src, MESSAGE *m);
int msg_send(struct s_proc *current, int dest, MESSAGE *m);
int send_recv(int function, int src_dest, MESSAGE *m);
void inform_int(int task_nr);
#endif